<?php

include_once("../module/checkA.php");
include_once("../../config.php");
include_once ("../../api/cls_json.php");

session_start();

$admin_user = $_SESSION['username'] !='' ? $_SESSION['username'] : $_SESSION['mid'];



$result = array('error' => 1, 'message' => '', 'content' => '');
$json  = new JSON;

if($admin_user  == ''){
	
	$result['error'] = "1";
	$result['content'] = "未知错误，请重新登陆操作";
	 
	die($json->encode($result));
	exit;	
	
}

//设置需要搜索的表格的前缀后缀
$table_suffix='order_list';//$plate['table_suffix'];
$table=$table_Prefix.$table_suffix;

$new_detail_nid=$_REQUEST['nid'];

$act = $_REQUEST['act'];

if($act == 'all_in'){
	
	$id_arr = explode(',',$new_detail_nid);
	
	foreach($id_arr as $val){
		
		$order_info = select_one_line_all_items($table_Prefix.$table_suffix ,"nid = ".$val);
		
		if($order_info['order_status'] == 0){
			$res = do_query(" update $table set order_status = '1' WHERE nid='$val'");
		}
	}
	$result['error'] = "0";
	$result['content'] = "订单出单成功";
	die($json->encode($result));
	exit;	
}
else{

	
	$order_info = select_one_line_all_items($table_Prefix.$table_suffix ," nid = '$new_detail_nid' ");
	
	if(!$order_info){
		$result['error'] = "1";
		$result['content'] = "当前订单状态有误";
		die($json->encode($result));
		exit;
	}
	
	if($order_info['status'] == '已出单'){
		$result['error'] = "1";
		$result['content'] = "当前订单已经是出单状态";
		die($json->encode($result));
		exit;
	}

	$collection_date = $_REQUEST['collection_date'];
	$remark = $_REQUEST['remark'];

	$res = do_query(" update $table set status = '已出单',collection_date = '$collection_date',remark = '$remark'  WHERE nid='$new_detail_nid'");

	if($res){
		$result['error'] = "0";
		$result['content'] = "订单出单成功";
	} else{
		$result['error'] = "1";
		$result['content'] = "订单出单失败";
	}

	die($json->encode($result));
	exit;	
}
?>


